const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    address: {},
    totalPrice: 0,
    orderList: []
  },
  //点击收货地址按钮 authSetting scope.address
  handleChooseAddress() {
    //获取权限状态
    wx.getSetting({
      success: (result) => {
        //获取权限状态
        const scopeAddress = result.authSetting["scope.address"];
        if (scopeAddress === true || scopeAddress === undefined) {
          wx.chooseAddress({
            success: (result1) => {
              console.log(result1);
              wx.setStorageSync("result1", result1);
            }
          });
        } else {
          //用户以前拒绝过授予权限，先诱导用户打开授权页面
          wx.openSetting({
            success: (result2) => {
              //可以直接调用收货地址代码
              wx.chooseAddress({
                success: (result1) => {
                  console.log(result1);
                  wx.setStorageSync("result1", result1);
                }
              });
             
            }
          });
        }
      }

    });
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function({ totalPrice }) {
    this.setData({
      totalPrice,
      orderList: app.globalData.orderCache
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    //获取缓存中的地址信息
    const address = wx.getStorageSync("result1");
    //给data赋值
    this.setData({
      address
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})